@(currentPage: Premios.Page, currentSortBy: String, currentOrder: String, codSorteo: Integer)

@****************************************
* Helper generating navigation links    *
****************************************@
@link(newPage:Int, newSortBy:String) = @{
    
    var sortBy = currentSortBy
    var order = currentOrder
    
    if(newSortBy != null) {
        sortBy = newSortBy
        if(currentSortBy == newSortBy) {
            if(currentOrder == "asc") {
                order = "desc"
            } else {
                order = "asc"
            }
        } else {
            order = "asc"
        }
    }
    
    // Generate the link
    routes.Sorteos.listPremios(newPage, sortBy, order, codSorteo)
    
}

@**********************************
* Helper generating table headers *
***********************************@
@header(key:String, title:String) = {
    <th class="@key.replace(".","_") header @if(currentSortBy == key) @{if(currentOrder == "asc") "headerSortDown" else "headerSortUp"}">
        <a href="@link(0, key)">@title</a>
    </th>
}

@main(Html("Lista de Premios")) {
    
    <h1 id="homeTitle">@Messages("premios.list.title", currentPage.getTotalRowCount)</h1>

    @if(flash.containsKey("success")) {
        <div class="alert-message warning">
            <strong>Hecho!</strong> @flash.get("success")
        </div>
    } 

    <div id="actions">  
        <br></br>
        <a class="btn success" id="add" href="@routes.Sorteos.newPremio(codSorteo)">Crear nuevo Premio</a>   
 
    </div>
    
    @if(currentPage.getTotalRowCount == 0) {
        
        <div class="well">
            <em>No hay premios que mostrar</em>
        </div>
        
    } else {
        
        <table class="computers zebra-striped">
            <thead>
                <tr>
                    @header("numPremio", "numero")
                    @header("descPremio", "Descripcion")
                    @header("cantidadPremio", "Cantidad")
                    @header("garantiaPremio", "Garantia")
                </tr>
            </thead>
            <tbody>

                @for(Premios <- currentPage.getList) {
                    <tr>
                        <td>@Premios.numPremio</td>
                        <td>
                            @Premios.descPremio                            
                        </td>
                        <td> 
                            @if(Premios.cantidadPremio    == null) {
                                <em>-</em>
                            } else {
                                @Premios.cantidadPremio   
                            }                                                     
                        </td>
                        <td>
                            @if(Premios.garantiaPremio    == null) {
                                <em>-</em>
                            } else {
                                @Premios.garantiaPremio   
                            }                          
                        </td>
                       
                    </tr>
                }

            </tbody>
        </table>

        <div id="pagination" class="pagination">
            <ul>
                @if(currentPage.hasPrev) {
                    <li class="prev">
                        <a href="@link(currentPage.getPageIndex - 1, null)">&larr; Anterior</a>
                    </li>
                } else {
                    <li class="prev disabled">
                        <a>&larr; Anterior</a>
                    </li>
                }
                <li class="current">
                    <a>Mostrando @currentPage.getDisplayXtoYofZ</a>
                </li>
                @if(currentPage.hasNext) {
                    <li class="next">
                        <a href="@link(currentPage.getPageIndex + 1, null)">Siguiente &rarr;</a>
                    </li>
                } else {
                    <li class="next disabled">
                        <a>Siguiente &rarr;</a>
                    </li>
                }
            </ul>
        </div>
        
    }
        
}

            